/**
 * Created by zycool on 2016/9/6.
 * 作业点维修记录 - 维修记录 - 详情 - 缺陷维修管理 - 管体缺陷
 */

;(function ($, window, document, undefined) {

    // 地址参数
    var task = {
        id: function () {
            var v = $('#JQ_id').val();
            if (v) {
                return v;
            }
            return '';
        }(),
        name: function () {
            var v = $('#JQ_name').val();
            if (v) {
                v = eval('"' + v + '"');
                return v;
            }
            return '';
        }(),
        code: function () {
            var v = $('#JQ_code').val();
            if (v) {
                v = eval('"' + v + '"');
                return v;
            }
            return '';
        }(),
        pipe: function () {
            var v = $('#JQ_pipe').val();
            if (v) {
                v = eval('"' + v + '"');
                return v;
            }
            return '';
        }()
    };

    // 已被转化的图片数量
    var count = 0;
    // 作业点图片总数量
    var work_pic = [];

    // 记录数据模板
    var repairWork = [
        {
            key: 'START_NODE', value: '管沟开挖', node: [
            {name: 'buriedDepth', title: '埋深(m)'},
            {name: 'depth', title: '深度(m)'},
            {name: 'difficultToRepair', title: '是否难以维修'},
            {name: 'length', title: '长度(m)'},
            {name: 'width', title: '宽度(m)'},
            {name: 'remark', title: '备注'},
            {name: 'imgList', title: '照片'}
        ]
        },
        {
            key: 'CORROSION_ENVIRONMENT_NODE', value: '腐蚀环境调查', node: [
            {name: 'deepRootedPlants', title: '根系植物'},
            {name: 'groundwater', title: '地下水'},
            {name: 'soilColor', title: '土壤颜色'},
            {name: 'soilCompactness', title: '土壤松紧度'},
            {name: 'soilHumidity', title: '土壤干湿度'},
            {name: 'soilLayer', title: '土壤分层描述'},
            {name: 'soilParticlesGroup', title: '土壤颗粒组划分'},
            {name: 'soilPh', title: 'PH值'},
            {name: 'soilResistivity', title: '土壤电阻率(Ω▪m)'},
            {name: 'soilSamplingNumber', title: '土壤取样编号'},
            {name: 'terrainGeomorphology', title: '地形地貌描述'},
            {name: 'remark', title: '备注'},
            {name: 'imgList', title: '照片'}
        ]
        },
        {
            key: 'COAT_SURVEY_NODE', value: '防腐层调查', node: [
            {name: 'appearance', title: '外观质量'},
            {name: 'coatingMaterial', title: '防腐层类型'},
            {name: 'coatingThicknessTest1', title: '剥离强度(N/cm)-测试1'},
            {name: 'coatingThicknessTest2', title: '剥离强度(N/cm)-测试2'},
            {name: 'coatingThicknessTest3', title: '剥离强度(N/cm)-测试3'},
            {name: 'coatingThicknessTest4', title: '剥离强度(N/cm)-测试4'},
            {name: 'electricSparkAmount', title: '电火花检测-漏点数'},
            {name: 'electricSparkTestVoltage', title: '电火花检测-检查电压（KV）'},
            {name: 'isPipeReplacement', title: '是否需要换管'},
            {name: 'peelingStrengthTest1', title: '厚度(mm)-测试1'},
            {name: 'peelingStrengthTest2', title: '厚度(mm)-测试2'},
            {name: 'peelingStrengthTest3', title: '厚度(mm)-测试3'},
            {name: 'peelingStrengthTest4', title: '厚度(mm)-测试4'},
            {name: 'pipeBodyTemperature', title: '管体温度(℃)'},
            {name: 'remark', title: '备注'},
            {name: 'imgList', title: '照片'}
        ]
        },
        {
            key: 'SURFACE_TREATMENT_NODE', value: '表面处理', node: [
            {name: 'anchorDepth', title: '锚纹深度(mm)'},
            {name: 'derustingGrade', title: '除锈等级'},
            {name: 'isPipeReplacement', title: '是否需要换管'},
            {name: 'remark', title: '备注'},
            {name: 'imgList', title: '照片'}
        ]
        },
        {
            key: 'CP_SURVEY_NODE', value: '阴保调查', node: [
            {name: 'acPotential', title: '交流干扰电压(V)'},
            {name: 'freeCorrosionPotential', title: '自然电位(-mV)'},
            {name: 'maxPotential', title: '直流干扰-最大值(mV)'},
            {name: 'minPotential', title: '直流干扰-最小值(mV)'},
            {name: 'onPotential', title: '通电电位(-mV)'},
            {name: 'polarizedPotential', title: '极化电位(-mV)'},
            {name: 'soilResistivity', title: '土壤电阻率'},
            {name: 'remark', title: '备注'},
            {name: 'imgList', title: '照片'}
        ]
        },
        {
            key: 'DEFECT_MEASURE_NODE', value: '缺陷测量', node: [
            {
                name: 'featureTypeCode', title: '测量方法', group: {
                /* 金属损失 */
                TDF_FEATURE_TYPE_JSSS: [
                    {name: 'mileage', title: '绝对距离(m)'},
                    {name: 'length', title: '长(mm)'},
                    {name: 'width', title: '宽(mm)'},
                    {name: 'depth', title: '深(mm)'},
                    {name: 'maxDepth', title: '峰值深度(%wt)'},
                    {name: 'clock', title: '时钟位置(h:min)'},
                    {name: 'actualLength', title: '实测 长(mm)'},
                    {name: 'actualWidth', title: '实测 宽(mm)'},
                    {name: 'actualDepth', title: '实测 深(mm)'},
                    {name: 'actualMaxdepth', title: '实测 峰值深度(%wt)'},
                    {name: 'actualClock', title: '实测 时钟位置(h:min)'},
                    {name: 'defectNumber', title: '缺陷编号'},
                    {name: 'featureSubType', title: '缺陷类型'},
                    {name: 'actualFeatureType', title: '实测缺陷类型'},
                    {name: 'actualX', title: '实测经度(°)'},
                    {name: 'actualY', title: '实测纬度(°)'},
                    {name: 'actualZ', title: '实测高度(°)'},
                    {name: 'planRepairMethod', title: '评价修复方法'},
                    {name: 'repairMethod', title: '变更修复方法'},
                    {name: 'repairWorkload', title: '工作量'},
                    {name: 'repairRemark', title: '变更修复方法原因'}
                ],
                /* 凹陷 */
                TDF_FEATURE_TYPE_AX: [
                    {name: 'mileage', title: '绝对距离(m)'},
                    {name: 'length', title: '长(mm)'},
                    {name: 'width', title: '宽(mm)'},
                    {name: 'depth', title: '深(mm)'},
                    {name: 'maxDepth', title: '峰值深度(%wt)'},
                    {name: 'clock', title: '时钟位置(h:min)'},
                    {name: 'actualLength', title: '实测 长(mm)'},
                    {name: 'actualWidth', title: '实测 宽(mm)'},
                    {name: 'actualDepth', title: '实测 深(mm)'},
                    {name: 'actualMaxdepth', title: '实测 峰值深度(%wt)'},
                    {name: 'actualClock', title: '实测 时钟位置(h:min)'},
                    {name: 'defectNumber', title: '缺陷编号'},
                    {name: 'featureSubType', title: '缺陷类型'},
                    {name: 'actualFeatureType', title: '实测缺陷类型'},
                    {name: 'actualX', title: '实测经度(°)'},
                    {name: 'actualY', title: '实测纬度(°)'},
                    {name: 'actualZ', title: '实测高度(°)'},
                    {name: 'planRepairMethod', title: '评价修复方法'},
                    {name: 'repairMethod', title: '变更修复方法'},
                    {name: 'repairWorkload', title: '工作量'},
                    {name: 'repairRemark', title: '变更修复方法原因'}
                ],
                /* 焊缝异常 */
                TDF_FEATURE_TYPE_HFYC: [
                    {name: 'mileage', title: '绝对距离(m)'},
                    {name: 'length', title: '长(mm)'},
                    {name: 'width', title: '宽(mm)'},
                    {name: 'clock', title: '时钟位置(h:min)'},
                    {name: 'actualLength', title: '实测 长(mm)'},
                    {name: 'actualWidth', title: '实测 宽(mm)'},
                    {name: 'actualClock', title: '实测 时钟位置(h:min)'},
                    {name: 'ndtReportNumber', title: '无损检测报告编号'},
                    {name: 'defectNumber', title: '缺陷编号'},
                    {name: 'featureSubType', title: '缺陷类型'},
                    {name: 'actualFeatureType', title: '实测缺陷类型'},
                    {name: 'actualX', title: '实测经度(°)'},
                    {name: 'actualY', title: '实测纬度(°)'},
                    {name: 'actualZ', title: '实测高度(°)'},
                    {name: 'planRepairMethod', title: '评价修复方法'},
                    {name: 'repairMethod', title: '变更修复方法'},
                    {name: 'repairWorkload', title: '工作量'},
                    {name: 'repairRemark', title: '变更修复方法原因'},
                    {name: 'defectDescription', title: '实测 缺陷描述'}
                ],
                /* 椭圆变形 */
                TDF_FEATURE_TYPE_TYBX: [
                    {name: 'mileage', title: '绝对距离(m)'},
                    {name: 'maxDeformation', title: '缺陷信息(最大变形量%OD)：'},
                    {name: 'length', title: '缺陷信息(长mm)：'},
                    {name: 'actualMaxDeformation', title: '实测 缺陷信息(最大变形量%OD)：'},
                    {name: 'actualLength', title: '实测 缺陷信息(长mm)：'},
                    {name: 'defectNumber', title: '缺陷编号'},
                    {name: 'featureSubType', title: '缺陷类型'},
                    {name: 'actualFeatureType', title: '实测缺陷类型'},
                    {name: 'actualX', title: '实测经度(°)'},
                    {name: 'actualY', title: '实测纬度(°)'},
                    {name: 'actualZ', title: '实测高度(°)'},
                    {name: 'planRepairMethod', title: '评价修复方法'},
                    {name: 'repairMethod', title: '变更修复方法'},
                    {name: 'repairWorkload', title: '工作量'},
                    {name: 'repairRemark', title: '变更修复方法原因'}
                ],
                /* 类裂纹 */
                TDF_FEATURE_TYPE_LLW: [
                    {name: 'mileage', title: '绝对距离(m)'},
                    {name: 'length', title: '长(mm)'},
                    {name: 'width', title: '宽(mm)'},
                    {name: 'depth', title: '深(mm)'},
                    {name: 'maxDepth', title: '峰值深度(%wt)'},
                    {name: 'clock', title: '时钟位置(h:min)'},
                    {name: 'actualLength', title: '实测 长(mm)'},
                    {name: 'actualWidth', title: '实测 宽(mm)'},
                    {name: 'actualDepth', title: '实测 深(mm)'},
                    {name: 'actualMaxdepth', title: '实测 峰值深度(%wt)'},
                    {name: 'actualClock', title: '实测 时钟位置(h:min)'},
                    {name: 'ndtReportNumber', title: '无损检测报告编号'},
                    {name: 'defectNumber', title: '缺陷编号'},
                    {name: 'featureSubType', title: '缺陷类型'},
                    {name: 'actualFeatureType', title: '实测缺陷类型'},
                    {name: 'actualX', title: '实测经度(°)'},
                    {name: 'actualY', title: '实测纬度(°)'},
                    {name: 'actualZ', title: '实测高度(°)'},
                    {name: 'planRepairMethod', title: '评价修复方法'},
                    {name: 'repairMethod', title: '变更修复方法'},
                    {name: 'repairWorkload', title: '工作量'},
                    {name: 'repairRemark', title: '变更修复方法原因'},
                    {name: 'defectDescription', title: '缺陷描述'}
                ],
                /* 损伤缺陷 */
                TDF_FEATURE_TYPE_SSQX: [
                    {name: 'mileage', title: '绝对距离(m)'},
                    {name: 'length', title: '长(mm)'},
                    {name: 'width', title: '宽(mm)'},
                    {name: 'depth', title: '深(mm)'},
                    {name: 'maxDepth', title: '峰值深度(%wt)'},
                    {name: 'clock', title: '时钟位置(h:min)'},
                    {name: 'actualLength', title: '实测 长(mm)'},
                    {name: 'actualWidth', title: '实测 宽(mm)'},
                    {name: 'actualDepth', title: '实测 深(mm)'},
                    {name: 'actualMaxdepth', title: '实测 峰值深度(%wt)'},
                    {name: 'actualClock', title: '实测 时钟位置(h:min)'},
                    {name: 'defectNumber', title: '缺陷编号'},
                    {name: 'featureSubType', title: '缺陷类型'},
                    {name: 'actualFeatureType', title: '实测缺陷类型'},
                    {name: 'actualX', title: '实测经度(°)'},
                    {name: 'actualY', title: '实测纬度(°)'},
                    {name: 'actualZ', title: '实测高度(°)'},
                    {name: 'planRepairMethod', title: '评价修复方法'},
                    {name: 'repairMethod', title: '变更修复方法'},
                    {name: 'repairWorkload', title: '工作量'},
                    {name: 'repairRemark', title: '变更修复方法原因'}
                ],
                /* 补丁信息 */
                TDF_FEATURE_TYPE_BDXX: [
                    {name: 'mileage', title: '绝对距离(m)'},
                    {name: 'length', title: '长(mm)'},
                    {name: 'width', title: '宽(mm)'},
                    {name: 'clock', title: '时钟位置(h:min)'},
                    {name: 'actualLength', title: '实测 长(mm)'},
                    {name: 'actualWidth', title: '实测 宽(mm)'},
                    {name: 'actualClock', title: '实测 时钟位置(h:min)'},
                    {name: 'defectNumber', title: '缺陷编号'},
                    {name: 'featureSubType', title: '缺陷类型'},
                    {name: 'actualFeatureType', title: '实测缺陷类型'},
                    {name: 'actualX', title: '实测经度(°)'},
                    {name: 'actualY', title: '实测纬度(°)'},
                    {name: 'actualZ', title: '实测高度(°)'},
                    {name: 'planRepairMethod', title: '评价修复方法'},
                    {name: 'repairMethod', title: '变更修复方法'},
                    {name: 'repairWorkload', title: '工作量'},
                    {name: 'repairRemark', title: '变更修复方法原因'}
                ]
            }
            },
            {name: 'remark', title: '备注'},
            {name: 'imgList', title: '照片'}
        ]
        },
        {
            key: 'REPAIR_NODE', value: '缺陷修复', node: [
            {
                name: 'repairMethodCode', title: '修复方法', group: {
                /* 复合材料补强修复 */
                PIC_TDF_REPAIR_COMPOSITES: [
                    {name: 'repairMethod', title: '修复方法'},
                    {name: 'repairMaterial', title: '修复材料'},
                    {name: 'repairLength', title: '修复长度(mm)'},
                    {name: 'repairLayer', title: '修复层数'},
                    {name: 'surfaceTemperature', title: '管表温度(℃)'},
                    {name: 'environmentalTemperature', title: '环境温度(℃)'},
                    {name: 'solidificationTime', title: '固化时间(min)'},
                    {name: 'hardness', title: '巴氏硬度(HBa)'},
                    {name: 'materialManufacturer', title: '修复材料厂商'}
                ],
                /* 钢质环氧套筒补强修复 */
                PIC_TDF_REPAIR_EPOXY_SLEEVE: [
                    {name: 'socketStructure', title: '套筒结构'},
                    {name: 'material', title: '管材'},
                    {name: 'wallThickness', title: '壁厚(mm)'},
                    {name: 'od', title: '外径(mm)'},
                    {name: 'repairLength', title: '修复长度(mm)'},
                    {name: 'environmentalTemperature', title: '环境温度(℃)'},
                    {name: 'surfaceTemperature', title: '管表温度(℃)'},
                    {name: 'perfusionProcess', title: '灌注工艺'},
                    {name: 'workload', title: '工作量(㎡)'},
                    {name: 'manufacturer', title: '生产厂商'}
                ],
                /* A和B型套筒补强修复 */
                PIC_TDF_REPAIR_ABTYPE_SLEEVE: [
                    {name: 'wallThickness', title: '套筒壁厚(mm)'},
                    {name: 'length', title: '套筒长度(mm)'},
                    {name: 'material', title: '管材'},
                    {name: 'environmentalTemperature', title: '环境温度(℃)'},
                    {name: 'surfaceTemperature', title: '管表温度(℃)'},
                    {name: 'weldingGrade', title: '焊材牌号'},
                    {name: 'weldingMethod', title: '焊接方法'}
                ],
                /* 换管 */
                PIC_TDF_REPAIR_REPLACE_PIPE: [
                    {name: 'startX', title: '起始位置x'},
                    {name: 'startY', title: '起始位置y'},
                    {name: 'startZ', title: '起始位置z'},
                    {name: 'startMileage', title: '起始绝对距离(m)'},
                    {name: 'endX', title: '终点位置x'},
                    {name: 'endY', title: '终点位置y'},
                    {name: 'endZ', title: '终点位置z'},
                    {name: 'endMileage', title: '终点绝对距离(m)'},
                    {name: 'material', title: '换管材质'},
                    {name: 'manuPipeType', title: '制管方式'},
                    {name: 'diameter', title: '管径(mm)'},
                    {name: 'wallThickness', title: '壁厚(mm)'},
                    {name: 'coatingMaterial', title: '防腐材料'},
                    {name: 'coatingGrade', title: '防腐等级'}
                ],
                /* 其他修复方法 */
                PIC_TDF_REPAIR_OTHER: []
            }
            },
            {name: 'remark', title: '备注'},
            {name: 'imgList', title: '照片'}
        ]
        },
        {
            key: 'HG_REPAIR_NODE', value: '焊接', node: [
            {name: 'wpsNumber', title: 'wps编号'},
            {name: 'ndtType', title: '无损检测类型'},
            {name: 'repairind', title: '是否返修'},
            {name: 'testingCompany', title: '检测单位'},
            {name: 'testDate', title: '检测日期'},
            {name: 'weldingMaterial', title: '焊接材质'},
            {
                name: 'weldList', title: '焊缝信息', node: [
                {name: 'gwwNumber', title: '环焊缝编号'},
                {name: 'x', title: 'X'},
                {name: 'y', title: 'Y'},
                {name: 'z', title: 'Z'}
            ]
            },
            {name: 'remark', title: '备注'},
            {name: 'imgList', title: '照片'}
        ]
        },
        {
            key: 'COAT_REPAIR_NODE', value: '防腐层修复', node: [
            {name: 'edmLeak', title: '电火花检漏(电压KV)'},
            {name: 'environmentalTemperature', title: '环境温度(℃)'},
            {name: 'isJoint', title: '是否为补口'},
            {name: 'materialManufacturer', title: '修复材料厂商'},
            {name: 'repairLength', title: '修复长度(mm)'},
            {name: 'repairMaterial', title: '修复材料'},
            {name: 'repairThickness', title: '修复厚度(mm)'},
            {name: 'surfaceTemperature', title: '管表温度(℃)'},
            {name: 'workload', title: '工作量(㎡)'},
            {name: 'remark', title: '备注'},
            {name: 'imgList', title: '照片'}
        ]
        },
        {
            key: 'END_NODE', value: '管沟回填', node: [
            {name: 'remark', title: '备注'},
            {name: 'imgList', title: '照片'}
        ]
        }
    ];

    // 加载详情
    if (task.id) {
        var $div = $('#JQ_all_work_record');
        var url = DyyBase.root_path + '/pbf/defectRepairMgr/queryRepairNode.json';
        DyyBase.ajax(url, {defectId: task.id}, function (dataset) {
            if (dataset.bool) {
                var data = DyyBase.clearNull(dataset.result);
                $('#JQ_name_span').text(task.name);
                for (var i = 0, len = data.length; i < len; i++) {
                    var $line = $('<div class="zy-record-line zy-pdf-area"></div>');
                    var span = '', div = '';
                    for (var j = 0, lens = repairWork.length; j < lens; j++) {
                        if (data[i].hasOwnProperty(repairWork[j]['key'])) {
                            if (data[i][repairWork[j]['key']]) {
                                var node_name = data[i][repairWork[j]['key']]['nodeName'];
                                node_name = (node_name && node_name != '-') ? node_name : repairWork[j]['value'];
                                var meta = '<div class="zy-record-meta l"><span title="' + node_name + '">' + node_name + '</span></div>';
                                var info = '';
                                if (repairWork[j].hasOwnProperty('node')) {
                                    for (var n = 0, lenth = repairWork[j]['node'].length; n < lenth; n++) {
                                        if (data[i][repairWork[j]['key']].hasOwnProperty(repairWork[j]['node'][n]['name'])) {
                                            if (repairWork[j]['node'][n]['name'] === 'imgList') {
                                                if (data[i][repairWork[j]['key']].hasOwnProperty('imgList')) {
                                                    if (data[i][repairWork[j]['key']]['imgList']) {
                                                        var type_empty = true;
                                                        if (data[i][repairWork[j]['key']]['imgList'].hasOwnProperty('ALL')) {
                                                            if (data[i][repairWork[j]['key']]['imgList']['ALL'] && data[i][repairWork[j]['key']]['imgList']['ALL'].length) {
                                                                var img_all = '';
                                                                for (var m = 0, lenths = data[i][repairWork[j]['key']]['imgList']['ALL'].length; m < lenths; m++) {
                                                                    img_all += '<span><a target="_blank" href="' + DyyBase.file_path + data[i][repairWork[j]['key']]['imgList']['ALL'][m]['path'] + '"><img crossorigin="anonymous" class="zy-work-pic" src="' + DyyBase.file_path + data[i][repairWork[j]['key']]['imgList']['ALL'][m]['path'] + '" onload="storeImage(this)" /></a></span>';
                                                                }
                                                                div += '<div class="zy-record-img"><label>现<br>场<br>照<br>片</label>' + img_all + '</div>';
                                                                type_empty = false;
                                                            }
                                                        }
                                                        if (data[i][repairWork[j]['key']]['imgList'].hasOwnProperty('REPAIR_BEFORE')) {
                                                            if (data[i][repairWork[j]['key']]['imgList']['REPAIR_BEFORE'] && data[i][repairWork[j]['key']]['imgList']['REPAIR_BEFORE'].length) {
                                                                var img_before = '';
                                                                for (var x = 0, len_x = data[i][repairWork[j]['key']]['imgList']['REPAIR_BEFORE'].length; x < len_x; x++) {
                                                                    img_before += '<span><a target="_blank" href="' + DyyBase.file_path + data[i][repairWork[j]['key']]['imgList']['REPAIR_BEFORE'][x]['path'] + '"><img crossorigin="anonymous" class="zy-work-pic" src="' + DyyBase.file_path + data[i][repairWork[j]['key']]['imgList']['REPAIR_BEFORE'][x]['path'] + '" onload="storeImage(this)" /></a></span>';
                                                                }
                                                                div += '<div class="zy-record-img"><label>修<br>复<br>前</label>' + img_before + '</div>';
                                                                type_empty = false;
                                                            }
                                                        }
                                                        if (data[i][repairWork[j]['key']]['imgList'].hasOwnProperty('REPAIR_DURING')) {
                                                            if (data[i][repairWork[j]['key']]['imgList']['REPAIR_DURING'] && data[i][repairWork[j]['key']]['imgList']['REPAIR_DURING'].length) {
                                                                var img_during = '';
                                                                for (var y = 0, len_y = data[i][repairWork[j]['key']]['imgList']['REPAIR_DURING'].length; y < len_y; y++) {
                                                                    img_during += '<span><a target="_blank" href="' + DyyBase.file_path + data[i][repairWork[j]['key']]['imgList']['REPAIR_DURING'][y]['path'] + '"><img crossorigin="anonymous" class="zy-work-pic" src="' + DyyBase.file_path + data[i][repairWork[j]['key']]['imgList']['REPAIR_DURING'][y]['path'] + '" onload="storeImage(this)" /></a></span>';
                                                                }
                                                                div += '<div class="zy-record-img"><label>修<br>复<br>中</label>' + img_during + '</div>';
                                                                type_empty = false;
                                                            }
                                                        }
                                                        if (data[i][repairWork[j]['key']]['imgList'].hasOwnProperty('REPAIR_AFTER')) {
                                                            if (data[i][repairWork[j]['key']]['imgList']['REPAIR_AFTER'] && data[i][repairWork[j]['key']]['imgList']['REPAIR_AFTER'].length) {
                                                                var img_after = '';
                                                                for (var z = 0, len_z = data[i][repairWork[j]['key']]['imgList']['REPAIR_AFTER'].length; z < len_z; z++) {
                                                                    img_after += '<span><a target="_blank" href="' + DyyBase.file_path + data[i][repairWork[j]['key']]['imgList']['REPAIR_AFTER'][z]['path'] + '"><img crossorigin="anonymous" class="zy-work-pic" src="' + DyyBase.file_path + data[i][repairWork[j]['key']]['imgList']['REPAIR_AFTER'][z]['path'] + '" onload="storeImage(this)" /></a></span>';
                                                                }
                                                                div += '<div class="zy-record-img"><label>修<br>复<br>后</label>' + img_after + '</div>';
                                                                type_empty = false;
                                                            }
                                                        }
                                                        if (data[i][repairWork[j]['key']]['imgList'].hasOwnProperty('NDTTYPE')) {
                                                            if (data[i][repairWork[j]['key']]['imgList']['NDTTYPE'] && data[i][repairWork[j]['key']]['imgList']['NDTTYPE'].length) {
                                                                var img_type = '';
                                                                for (var ab = 0, len_ab = data[i][repairWork[j]['key']]['imgList']['NDTTYPE'].length; ab < len_ab; ab++) {
                                                                    img_type += '<span><a target="_blank" href="' + DyyBase.file_path + data[i][repairWork[j]['key']]['imgList']['NDTTYPE'][ab]['path'] + '"><img crossorigin="anonymous" class="zy-work-pic" src="' + DyyBase.file_path + data[i][repairWork[j]['key']]['imgList']['NDTTYPE'][ab]['path'] + '" onload="storeImage(this)" /></a></span>';
                                                                }
                                                                div += '<div class="zy-record-img"><label>无<br>损<br>检<br>测<br>照<br>片</label>' + img_type + '</div>';
                                                                type_empty = false;
                                                            }
                                                        }
                                                        if (data[i][repairWork[j]['key']]['imgList'].hasOwnProperty('WELDWORKTYPE')) {
                                                            if (data[i][repairWork[j]['key']]['imgList']['WELDWORKTYPE'] && data[i][repairWork[j]['key']]['imgList']['WELDWORKTYPE'].length) {
                                                                var img_work = '';
                                                                for (var cd = 0, len_cd = data[i][repairWork[j]['key']]['imgList']['WELDWORKTYPE'].length; cd < len_cd; cd++) {
                                                                    img_work += '<span><a target="_blank" href="' + DyyBase.file_path + data[i][repairWork[j]['key']]['imgList']['WELDWORKTYPE'][cd]['path'] + '"><img crossorigin="anonymous" class="zy-work-pic" src="' + DyyBase.file_path + data[i][repairWork[j]['key']]['imgList']['WELDWORKTYPE'][cd]['path'] + '" onload="storeImage(this)" /></a></span>';
                                                                }
                                                                div += '<div class="zy-record-img"><label>焊<br>接<br>作<br>业<br>指<br>导<br>书</label>' + img_work + '</div>';
                                                                type_empty = false;
                                                            }
                                                        }
                                                        if (type_empty) {
                                                            div += '<div class="zy-record-img"><label>现<br>场<br>照<br>片</label></div>';
                                                        }
                                                    }
                                                }
                                            } else {
                                                if (repairWork[j]['node'][n]['name'] === 'remark' || repairWork[j]['node'][n]['name'] === 'terrainGeomorphology' || repairWork[j]['node'][n]['name'] === 'redoxPotential') {
                                                    span += '<p class="zy-work-record-remark">' + repairWork[j]['node'][n]['title'] + '：<em>' + data[i][repairWork[j]['key']][repairWork[j]['node'][n]['name']] + '</em></p>';
                                                } else if (repairWork[j]['node'][n]['name'] === 'weldList') {
                                                    span += '<p class="zy-work-record-remark">环焊缝信息：</p>';
                                                    if (data[i][repairWork[j]['key']].hasOwnProperty(repairWork[j]['node'][n]['name'])) {
                                                        if (data[i][repairWork[j]['key']][repairWork[j]['node'][n]['name']]) {
                                                            for (var a = 0, len_a = data[i][repairWork[j]['key']][repairWork[j]['node'][n]['name']].length; a < len_a; a++) {
                                                                for (var b = 0, len_b = repairWork[j]['node'][n]['node'].length; b < len_b; b++) {
                                                                    if (data[i][repairWork[j]['key']][repairWork[j]['node'][n]['name']][a].hasOwnProperty(repairWork[j]['node'][n]['node'][b]['name'])) {
                                                                        if (data[i][repairWork[j]['key']][repairWork[j]['node'][n]['name']][a][repairWork[j]['node'][n]['node'][b]['name']]) {
                                                                            span += '<span title="' + repairWork[j]['node'][n]['node'][b]['title'] + '：' + data[i][repairWork[j]['key']][repairWork[j]['node'][n]['name']][a][repairWork[j]['node'][n]['node'][b]['name']] + '">' + repairWork[j]['node'][n]['node'][b]['title'] + '：<em>' + data[i][repairWork[j]['key']][repairWork[j]['node'][n]['name']][a][repairWork[j]['node'][n]['node'][b]['name']] + '</em></span>'
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                } else if (repairWork[j]['node'][n]['name'] === 'repairMethodCode') {
                                                    if (data[i][repairWork[j]['key']].hasOwnProperty('repairMethodCode')) {
                                                        if (repairWork[j]['node'][n]['group'][data[i][repairWork[j]['key']]['repairMethodCode']]) {
                                                            var temp_group = repairWork[j]['node'][n]['group'][data[i][repairWork[j]['key']]['repairMethodCode']];
                                                            for (var c = 0, len_c = temp_group.length; c < len_c; c++) {
                                                                span += '<span title="' + temp_group[c]['title'] + '：' + data[i][repairWork[j]['key']][temp_group[c]['name']] + '">' + temp_group[c]['title'] + '：<em>' + data[i][repairWork[j]['key']][temp_group[c]['name']] + '</em></span>';
                                                            }
                                                        }
                                                    }
                                                } else if (repairWork[j]['node'][n]['name'] === 'featureTypeCode') {
                                                    if (data[i][repairWork[j]['key']].hasOwnProperty('featureTypeCode')) {
                                                        if (repairWork[j]['node'][n]['group'][data[i][repairWork[j]['key']]['featureTypeCode']]) {
                                                            var temp_group2 = repairWork[j]['node'][n]['group'][data[i][repairWork[j]['key']]['featureTypeCode']];
                                                            for (var d = 0, len_d = temp_group2.length; d < len_d; d++) {
                                                                if(temp_group2[d]['name'] === 'defectDescription' || temp_group2[d]['name'] === 'repairRemark'){
                                                                    span += '<p class="zy-work-record-remark">' + temp_group2[d]['title'] + '：<em>' + data[i][repairWork[j]['key']][temp_group2[d]['name']] + '</em></p>';
                                                                }else{
                                                                    span += '<span title="' + temp_group2[d]['title'] + '：' + data[i][repairWork[j]['key']][temp_group2[d]['name']] + '">' + temp_group2[d]['title'] + '：<em>' + data[i][repairWork[j]['key']][temp_group2[d]['name']] + '</em></span>';
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                else {
                                                    span += '<span title="' + repairWork[j]['node'][n]['title'] + '：' + data[i][repairWork[j]['key']][repairWork[j]['node'][n]['name']] + '">' + repairWork[j]['node'][n]['title'] + '：<em>' + data[i][repairWork[j]['key']][repairWork[j]['node'][n]['name']] + '</em></span>';
                                                }
                                            }
                                        }
                                    }
                                }
                                info = meta + '<div class="zy-record-body l"><div class="zy-record-info">' + span + '</div>' + div + '</div>';
                                $line.append(info).append('<div class="clear"></div>');
                            }
                        }
                    }
                    if ($line.html()) {
                        $div.append($line);
                    }
                }
            }
        });
    }

    // 返回列表
    $('#JQ_goback_list').click(function () {
        window.location.href = DyyBase.root_path + '/pbf/RepairTask/init.html';
    });

    // 返回详情
    $('#JQ_goback_details').click(function () {
        window.history.go(-1);
    });

    // 将图片临时存储
    window.storeImage = function (img) {
        work_pic.push(img);
    };

    // 导出pdf操作
    function exportPDF() {
        DyyBase.isLogin(function () {
            $(this).EXPT({
                type: 'name',
                name: task.pipe + task.name + task.code + '作业点维修记录',
                yesBtnAct: function (callback, fname) {
                    callback();
                    canvasPdf.exportHtmlPdf({
                        dom: $('#JQ_all_work_record'),
                        server: DyyBase.root_path + '/comm/downImgPdf.json',
                        param: {
                            fileName: fname,
                            name: task.name + task.code + '作业点维修记录'
                        }
                    });
                }
            });
        });
    }

    // 将图片base64转码
    function imgBase64(pics) {
        if (pics[count]) {
            try {
                var canvas = document.createElement('canvas');
                canvas.width = 110;
                canvas.height = 95;
                var ctx = canvas.getContext('2d');
                ctx.drawImage(pics[count], 0, 0, 110, 95);
                var ext = pics[count].src.substring(pics[count].src.lastIndexOf('.') + 1).toLowerCase();
                var dataURL = canvas.toDataURL('image/' + ext);
                pics[count].src = dataURL;
                pics[count].removeAttribute('onload');
                pics[count].removeAttribute('crossorigin');
                count++;
                if (pics[count]) {
                    imgBase64(pics);
                } else {
                    if (count === work_pic.length) {
                        exportPDF();
                    }
                }
            } catch (e) {
                throw new Error(e.message);
            }
        }
    }

    // 导出pdf
    $('#JQ_export_pdf').click(function () {

        if (count == 0 && work_pic.length > 0) {
            imgBase64(work_pic);
        } else {
            exportPDF();
        }

    });

})(jQuery, window, document);